<template>
  <div class="binding">
    <svg-icon :icon-class="message === '绑定成功！' ? 'success' : message === '绑定失败！' ? 'error2' : ''" style="margin-right: 5px" />{{ message }}
  </div>
</template>

<script>
import { usersBinding } from '@/api/system/user'
export default {
  name: 'BindingSuccess',
  data() {
    return {
      code: '',
      userName: '',
      message: ''
    }
  },
  // 因为是在当前页面添加code的，界面没有刷新，只是添加参数，所以就必须监测路由参数的变化
  watch: {
    '$route.query': {
      handler(newVal, oldVal) {
        console.info(newVal, oldVal)
        this.code = this.$route.query['code']
        this.userName = this.$route.query['userName']
        if (this.code && this.userName) {
          this.getStaffInfo()
        }
      },
      deep: true,
      immediate: true
    }
  },
  methods: {
    getStaffInfo() { // 验证企业微信二维码扫码登录
      const params = {
        code: this.code,
        userName: this.userName
      }
      usersBinding(params).then(res => {
        this.message = res
      })
    }
  }
}
</script>

<style scoped>
.binding{
  margin-top: 100px;
  text-align: center;
}
</style>
